package com.study.zkyxgs1.config;

import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * redisson分布式锁配置
 * @author weixiaochun
 * @date 2022/6/18 13:59
 */
@Configuration
public class MyRedissonConfig {

    @Value("${spring.redis.host}")
    private String host;

    @Value("${spring.redis.port}")
    private String port;

    @Bean(destroyMethod="shutdown")
    public RedissonClient redisson() {
        //创建配置
        Config config = new Config();
        config.useSingleServer().setAddress("redis://" + host + ":" + port);

        //根据Config创建出RedissonClient实例
        return Redisson.create(config);
    }
}
